<script type="text/javascript">
    $(document).ready(function() {
        // Refresh every 5 minutes to prevent logout
        setTimeout(function() {
            window.location.reload();
        }, 300000);
    });
</script>

<?php
    function printBookingList($bookings) {
        $rowCount = 0;
?>
        <table>
          <thead>
            <tr>
              <th>ID</th>
              <th>Booking time</th>
              <th>Food time</th>
              <th>Child name</th>
              <th>Contact name</th>
              <th>Contact phone</th>
              <th>Room</th>
              <th>Guests</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
            <?php
                foreach ($bookings as $booking) {
                    $rowCount++;
            ?>
            <tr class="<?php echo ($rowCount % 2 == 0 ? "even" : "odd"); ?>">
              <td class="id"><?php echo $booking->getId() ?></td>
              <td><?php echo date('g:ia', strtotime($booking->getBookingDatetime())) ?></td>
              <td><?php echo date('g:ia', strtotime($booking->getFoodDatetime())) ?></td>
              <td><?php echo $booking->getSubjectName() ?></td>
              <td><?php echo $booking->getContactName() ?></td>
              <td><?php echo $booking->getContactPhone() ?></td>
              <td><?php echo $booking->getRoom() ?></td>
              <td class="centered" style="<?php if ($booking->getGuestArrivedCount() > $booking->getGuestCount()) { echo "color: red;";} ?>"><strong><?php echo $booking->getGuestArrivedCount() ?> / <?php echo $booking->getGuestCount() ?></strong></td>
              <td class="actions">
                <strong><a href="<?php echo url_for('bookings/guests?id='.$booking->getId().'&add=1') ?>" style="<?php if ($booking->getGuestArrivedCount() >= $booking->getGuestCount()) { echo "color: red;";} ?>">+1 guest</a></strong>
                <?php if ($booking->getGuestArrivedCount() > 0) { ?> | <a href="<?php echo url_for('bookings/guests?id='.$booking->getId().'&minus=1') ?>">-1 guest</a><?php } ?>
                | <a href="<?php echo url_for('bookings/show?id='.$booking->getId()) ?>">show details</a>
                | <a href="<?php echo url_for('bookings/edit?id='.$booking->getId()) ?>">edit details</a>
            </tr>
            <?php
                }
            ?>
          </tbody>
        </table>
<?php
    }
    
    if (isset($bookings) && count($bookings)) {
        echo "<div class='section'>";
        echo "<h2>Today's parties</h2>" . PHP_EOL;
        printBookingList($bookings);
        echo "</div>";
    }
?>

<div class='section'>
    <a href='<?php echo url_for('bookings/index') ?>'>Show full bookings list</a>
</div>

